<template>
	<view class="login_box">
		<view class="">
			<image src="../../static/img/logo.png" class="logo_img" mode=""></image>
		</view>
		<view class="text_code">
			请输入邀请码
		</view>
		<u-message-input @finish='finish' width='100' inactive-color='#ff365d' :maxlength="6" mode="bottomLine">
		</u-message-input>
		<view class="btn">
			<u-button shape="circle" type='primary' @click="submit">确定登陆</u-button>

		</view>
	</view>
</template>

<script>
	import getLocationInfo from '@/mixin/getLocationInfo.js'
	import cacheFunc from '@/utils/cache.js'
	export default {
		mixins: [getLocationInfo],
		data() {
			return {
				value: '',
				isLogin: false,
				telPhone: ''
			};
		},
		onLoad(e) {
			if (e) {
				console.log(e, '233')
				this.telPhone = e.phone
			}
		},
		methods: {
			finish(e) {
				console.log(e, 'eeee')
				this.value = e
				this.isLogin = true
			},
			submit() {
				if (this.value.length === 6) {
					this.$u.api.checkInvitationCode({
						telPhone: this.telPhone,
						inCode: this.value
					}).then(res => {
						this.onReady()
						console.log(res, '登录')
						cacheFunc.setCache('userInfo', res)
						cacheFunc.setCache('token', res.token)
						uni.showLoading({
							title: '登录成功,跳转中~~'
						})
						setTimeout(() => {
							uni.hideLoading()
							uni.switchTab({
								url: '/pages/index/index'
							})
						}, 1000)
					})
				} else {
					this.$u.toast('请填写完整邀请码!');
				}
			}
		}
	}
</script>

<style lang="scss">
	.btn {
		padding: 0 30rpx;
		margin-top: 40rpx;
	}

	.login_box {
		text-align: center;
		margin-top: 260rpx;

		.text_code {
			color: #000000;
			font-size: 30rpx;
			margin-top: 30rpx;
			text-align: left;
			margin-left: 50rpx;
		}

		.logo_img {
			width: 170rpx;
			height: 170rpx;
			// text-align: center;
		}
	}
</style>
